Beginning C++17 by Ivor Horton & Peter Van Weert

Beginning C++17 by Ivor Horton & Peter Van Weert

Author:Ivor Horton & Peter Van Weert
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


Using the assert() Macro

The assert() preprocessor macro is defined in the Standard Library header cassert. This enables you to test logical expressions in your program. Including a line of the form assert(expression) results in code that causes the program to be terminated with a diagnostic message if expression evaluates to false. We can demonstrate this with this simple example:

// Ex10_09.cpp

// Demonstrating assertions

#include <iostream>

#include <cassert>

int main()

{

int y {5};

for (int x {}; x < 20; ++x)

{

std::cout << "x = " << x << " y = " << y << std::endl;

assert(x < y);

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.